package first.niuke.huawei.mediumDifficulty;

/**
 * @ClassName HJ67
 * @description:
 * @author: 荣燊
 * @create: 2021-07-08 12:58
 **/
public class HJ67 {
    //  24点游戏算法


    //
    static int flag = 0;
    static int[] visit = new int[4];
    static double[] ints;

    public static void main(String[] args) {
        // 只有四个数
        ints = new double[]{1, 2, 3, 4};
        dfs(-1, 0);
        System.out.println(flag);
    }

    static void dfs(int step, double sum) {
        if (step == 3 && sum == 24) {
            flag = 1;
            return ;
        } else {
            step++;
            for (int i=0; i<4; i++) {
                // 表示这一位没有被用
                if (visit[i] == 0) {
                    visit[i] = 1; //
                    dfs(step,sum+ints[i]);
                    dfs(step,sum-ints[i]);
                    dfs(step,sum*ints[i]);
                    dfs(step,sum/ints[i]);

                    // 回溯
                    visit[i] = 0;
                }
            }
        }

    }
}
